from crcmod import mkCrcFun
import os,shutil,string

g=mkCrcFun(0x104C11DB7,rev=False)

def getCrc(filename):
    crc     = hex(g(filename.lower()))
    nicecrc = str(crc[2:-1]).lower()
    #fixcrc  = nicecrc.rjust(8,'0')
    return str(nicecrc)


DEF_1    = 'iso9660://'                 ## for a data dvd/cd
DEF_2    = 'smb://KILLER/PCDVD/'        ## samba share
DEF_3    = 'smb://KILLER/MP3/'          ## samba share
DEF_4    = 'e:\\MP3-DISC4\\'            ## standard xbox/pc path
DEF_5    = 'e:\\MP3-DISC5\\'            ## standard xbox/pc path

PCROOT   = 'e:\\MP3\\'
TMPCOPY  = 'e:\\Thumbs\\Music\\'
HASHCPY  = 'e:\\Thumbs\\Music - Hash\\'
PICS1    = 'e:\\Thumbs\\Music - Empty Pics\\'
PICS2    = 'e:\\Thumbs\\Music - Good Pics\\'
NOFILE   = 'e:\\Thumbs\\Filelist.txt'
FILEARR  = {}


def CreateCrc(From,To,Path): # Search through the files and create the CRC
    for File in os.listdir(From)    :
        if File.endswith('.jpg')    :
            shortname = File[:-4]
            ToDir     = str(Path + shortname).lower()
            crc       = getCrc(ToDir)
            ext       = '.tbn'
            print '-- Hash:'+ str(crc)+ext +'-- '+ str(ToDir)
            shutil.copy(str(From) + str(File),str(HASHCPY) + str(crc) + ext)

## My little routine to create my hash files.
##
##for i in [PICS2,PICS1]:
##    for j in [DEF_1,DEF_2]:
##        CreateCrc(i,HASHCPY,j)

#### This is the call that will return the corrent hash value ###
